package com.muqi.app.qlearn.adapter;

import java.util.List;

import com.easemob.easeui.widget.CircularImage;
import com.muqi.app.network.http.GlideImageUtils;
import com.muqi.app.qlearn.modles.CommentBean;
import com.muqi.app.qlearn.modles.PersonBean;
import com.muqi.app.qlearn.student.R;
import com.muqi.app.user.db.ChildBean;
import com.muqi.app.user.db.MyClassStudent;
import com.muqi.app.user.widget.CircularImageView;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MyChildAdapter extends BaseAdapter {
	private Context context;
	private List<ChildBean> listData;
	private boolean isShow = false;
	private OnChildDelete childDelete;

	public void setChildDelete(OnChildDelete childDelete) {
		this.childDelete = childDelete;
	}

	public MyChildAdapter(Context context, List<ChildBean> listData,
			boolean isShow) {
		this.context = context;
		this.listData = listData;
		this.isShow = isShow;
	}

	@Override
	public int getCount() {
		return listData == null ? 10 : listData.size();
	}

	@Override
	public ChildBean getItem(int position) {
		return listData.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@SuppressLint("InflateParams")
	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		final ChildBean itemInfo = listData.get(position);
		if (convertView == null) {
			holder = new ViewHolder();

			convertView = LayoutInflater.from(context).inflate(
					R.layout.item_my_child, null);

			holder.itemAvatar = (CircularImageView) convertView
					.findViewById(R.id.item_avator);
			holder.itemName = (TextView) convertView
					.findViewById(R.id.item_name);
			holder.itemRight = (ImageView) convertView
					.findViewById(R.id.itemRight);
			holder.itemDelete = (ImageView) convertView
					.findViewById(R.id.itemDelete);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		/*
		 * if (isShow) { holder.itemRight.setVisibility(View.VISIBLE); } else {
		 * holder.itemRight.setVisibility(View.GONE); }
		 */
		holder.itemName.setText(itemInfo.name);
		GlideImageUtils.setAvatar(context, itemInfo.avatar_02,
				holder.itemAvatar);
		holder.itemDelete.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				if (childDelete != null) {
					childDelete.onChildClick(position);
				}

			}
		});

		return convertView;
	}

	private class ViewHolder {
		CircularImageView itemAvatar;
		TextView itemName;
		ImageView itemRight;
		ImageView itemDelete;

	}

	public interface OnChildDelete {
		void onChildClick(int position);
	}
}
